package com.grq.mis.validate;

import org.springframework.util.StringUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class FhtValidate {

    /**
     * 判断是否是日期的字符串
     * 格式 yyyy-MM-dd
     * @param dateString
     * @return
     */
    public static boolean isDate(String dateString){
        if (StringUtils.isEmpty(dateString)){
            return false;
        }
        if (dateString.length() != 10){
            return false;
        }
        return isSimpleDatetime(dateString,"yyyy-MM-dd");
    }

    private static boolean isSimpleDatetime(String dateString, String pattern) {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        boolean dateFlag = true;
        try {
            Date date = sdf.parse(dateString);
        } catch (ParseException e) {
            dateFlag = false;
        }
        return dateFlag;
    }

}
